
function favlist(favlist = [], action = { type: '', payload: null }) {
    //对state进行深拷贝
    var newstate = JSON.parse(JSON.stringify(favlist));

    switch (action.type) {
        case 'ADD':
            newstate = action.payload;
            // console.log(newstate);
            return newstate;
        case 'CEL': /* 代码 */
            var index = newstate.findIndex((item) => {
                // console.log(item.id);
                return item.id == action.payload
            })
            // console.log(index);
            newstate.splice(index, 1);
            console.log(newstate);
            return newstate
        case 'RESET': /* 代码 */  return newstate;

        default: return favlist;
    }
}

export default favlist;